package cn.kbyue.security.service;

import cn.kbyue.security.entity.KbPermission;
import cn.kbyue.security.entity.KbRole;
import cn.kbyue.security.entity.RolePermissions;
import java.util.Collections;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * @author xlang
 * @version 0.0.1
 * @date 2021/9/14 19:58
 */
@Service
public class RolePermissionService {

    /**
     * 静态用户角色权限列表
     */
    public List<RolePermissions> getAllRolePermission() {
        return data();
    }

    /**
     * 用户的角色权限列表
     * @param userId userId
     */
    public List<RolePermissions> getUserRolePermission(String userId) {
        if ("10001".equals(userId)) {
            return data();
        }
        return Collections.emptyList();
    }

    private List<RolePermissions> data() {
        KbRole kbRole = new KbRole();
        kbRole.setId("1");
        kbRole.setCode("admin");
        kbRole.setName("管理员");

        KbPermission kbPermission = new KbPermission();
        kbPermission.setId(1);
        kbPermission.setName("查询用户列表");
        kbPermission.setCode("list:user");
        kbPermission.setStatus(0);
        kbPermission.setUrl("/list/user");

        RolePermissions permissions = new RolePermissions();
        permissions.setPermission(Collections.singletonList(kbPermission));
        permissions.setRole(kbRole);
        return Collections.singletonList(permissions);
    }
}
